human-format-rs
Rust Port of human-format from node, formatting numbers for us, while the machines are still at bay.
Master | Develop |
---|---|
What is human_format?
The primary purpose for this crate is to format numbers in a customizable fashion based around magnitudes. It is inspired by the human-format package and the hope is to ultimately provide an idiomatic rust port.
Usage
- Add this package as a dependency
[]
= "1.0"
- Print some human readable strings
Examples
// 1.00 k
new
.format );
// 1.34 k
new
.with_decimals
.format;
// 1.3 k
new
.with_decimals
.format;
// 1.3B
new
.with_decimals
.with_separator
.format;
// 1.00 - k
new
.with_separator
.format;
// Define your own scales as you see fit
let mut custom_binary_scales = new;
custom_binary_scales
.with_base
.with_suffixes;
// 1.00 kB
new
.with_scales
.with_units
.format;
// 1.00 kiB
new
.with_scales
.with_units
.format;
For more examples please consult tests/demo.rs